package framework.selfdemo.com.draw;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by zhangruntao on 17/1/5.
 */

public class TaijiView extends View{

    //定义两个画笔，分别为白和黑
    private Paint whitePaint;
    private Paint blackPaint;

    private Paint testBoundPaint;

    public TaijiView(Context context) {
        this(context,null);
    }

    public TaijiView(Context context, AttributeSet attrs) {
        this(context, attrs,0);
    }

    public TaijiView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        whitePaint = new Paint();
        whitePaint.setColor(Color.WHITE);
        whitePaint.setAntiAlias(true);

        blackPaint = new Paint();
        blackPaint.setColor(Color.BLACK);
        blackPaint.setAntiAlias(true);

        testBoundPaint = new Paint();
        testBoundPaint.setColor(Color.argb(55,66,6,66));
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawColor(Color.parseColor("#bdbdbd"));

        //定义中心点
        Point point = new Point(canvas.getWidth() / 2,canvas.getHeight() / 2);
        //定位中心点
        canvas.translate(point.x,point.y);

        //100为padding值
        int radius = canvas.getWidth() / 2 - 100;
        RectF drawBound = new RectF(-radius,-radius,radius,radius);
        canvas.drawRect(drawBound,testBoundPaint);
        canvas.drawArc(drawBound,-90,180,true,whitePaint);
        canvas.drawArc(drawBound,90,180,true,blackPaint);

        int smallRadius = radius / 2;
        canvas.drawCircle(0,-smallRadius,smallRadius,blackPaint);
        canvas.drawCircle(0,smallRadius,smallRadius,whitePaint);

        int dotRadius = smallRadius / 4;
        canvas.drawCircle(0,-smallRadius,dotRadius,whitePaint);
        canvas.drawCircle(0,smallRadius,dotRadius,blackPaint);
    }
}
